/*!
 * 新手引导模块
 */
define( [ 'jquery' ], function( $ ) {
  var msg = $( '.guide_wrap #msg' ).val();
  var _var = $( 'input#login_time' ).val();
  var _ulr = window.location.pathname;
  if ( _var == '1' && msg != 'null' && msg ) {
    //sessionStorage.pagecount=1;
    //location.href="/resource/article";
    // if (!sessionStorage.article && sessionStorage.article != 1) {
    //   sessionStorage.article = 1;
    // }
    // if (!sessionStorage.my_mpnews && sessionStorage.my_mpnews != 1) {
    //   sessionStorage.my_mpnews = 1;
    // }
    // if (!sessionStorage.sending && sessionStorage.sending != 1) {
    //   sessionStorage.sending = 1;
    // }
    // if (!sessionStorage.my_account && sessionStorage.my_account != 1) {
    //   sessionStorage.my_account = 1;
    // }
    // if (!sessionStorage.account_bind && sessionStorage.account_bind != 1) {
    //   sessionStorage.account_bind = 1;
    // }
  };


  $( function() {
    setTimeout( function() {
      $( '.notice_bar' ).show();
    }, 1000 );
    var head_search_type = null;
    var head_search_key = null;
    var search_address = null;
    var address_array = {
      'art': '/search/articles?search_type=art',
      'image': '/search/images?search_type=image',
      'gzh': '/search/account?search_type=gzh',
      'tpc': '/topic'
    };
    //新手向导

    $( '.new_guide' ).click( function() {
      $( '.guide_wrap' ).css( 'background', 'url(__FORJS__/images/guide/guide_bg.png) repeat-y center top' );
      sessionStorage.pagecount = 1;
      location.href = "/resource/article";
    } );
    $( '.guide_jingr .xia a:first-child' ).click( function() {
      sessionStorage.pagecount = 1;
    } );
    $( '.guide_faxian .caoz a:first-child' ).click( function() {
      $( '.guide_wrap>div' ).hide();
      $( '.guide_hecheng' ).fadeIn();
    } );
    $( '.guide_hecheng .caoz a:first-child' ).click( function() {
      $( '.guide_wrap' ).css( 'background', 'none' );
      $( '.guide_wrap>div' ).hide();
      $( '.guide_hechengqi' ).fadeIn();
      $( ".sidebar" ).css( {
        right: '0px'
      } );
    } );
    $( '.guide_hechengqi .caoz a:first-child' ).click( function() {
      sessionStorage.pagecount = 2;
    } );
    $( '.guide_chuangz .caoz a:first-child' ).click( function() {
      sessionStorage.pagecount = 3;
    } );
    $( '.guide_tuis .caoz a:first-child' ).click( function( e ) {
      if ( $( '#register-guide' ).length ) {
        e.preventDefault();
        sessionStorage.pagecount = 999;
        $( '.guide_wrap' ).hide();
        $( '.guide_wrap>div' ).hide();
        $( 'body' ).css( 'overflow', '' );
        if ( $( '#login_type' ).val() == 'oauth' ) {
          $( '#register-guide' ).modal( 'show' );
        }
      } else {
        sessionStorage.pagecount = 4;
      }
    } );
    $( '.guide_jingr .xia a:last-child,.guide_wrap>div .caoz a:last-child,.guide_zhangh .caoz a:first-child,.guide_jingr .close' ).click( function() {
      sessionStorage.pagecount = 999;
      $( '.guide_wrap' ).hide();
      $( '.guide_wrap>div' ).hide();
      $( 'body' ).css( 'overflow', '' );
      if ( $( '#login_type' ).val() == 'oauth' ) {
        $( '#register-guide' ).modal( 'show' );
      }

    } );
    if ( sessionStorage.pagecount == 1 && _ulr == '/resource/article' ) {
      $( '.guide_wrap' ).fadeIn();
      $( '.guide_wrap>div' ).hide();
      $( '.guide_faxian' ).fadeIn();
      $( 'body' ).css( 'overflow', 'hidden' );
    } else if ( sessionStorage.pagecount == 1 && _ulr != '/resource/article' && _var == '0' ) {
      sessionStorage.pagecount = 999;
      $( '.guide_wrap' ).hide();
      $( '.guide_wrap>div' ).hide();
      $( 'body' ).css( 'overflow', '' );
    }
    if ( sessionStorage.pagecount == 2 && _ulr == '/my_mpnews' ) {
      $( '.guide_wrap' ).css( 'background', 'url(__FORJS__/images/guide/guide_bg.png) repeat-y center top' );
      $( '.guide_wrap' ).fadeIn();
      $( '.guide_wrap>div' ).hide();
      $( '.guide_chuangz' ).fadeIn();
      $( 'body' ).css( 'overflow', 'hidden' );
    } else if ( sessionStorage.pagecount == 2 && _ulr != '/my_mpnews' ) {
      sessionStorage.pagecount = 999;
      $( '.guide_wrap' ).hide();
      $( '.guide_wrap>div' ).hide();
      $( 'body' ).css( 'overflow', '' );
    }
    if ( sessionStorage.pagecount == 3 && _ulr == '/sending' ) {
      $( '.guide_wrap' ).fadeIn();
      $( '.guide_wrap>div' ).hide();
      $( '.guide_tuis' ).fadeIn();
      $( 'body' ).css( 'overflow', 'hidden' );
    } else if ( sessionStorage.pagecount == 3 && _ulr != '/sending' ) {
      sessionStorage.pagecount = 999;
      $( '.guide_wrap' ).hide();
      $( '.guide_wrap>div' ).hide();
      $( 'body' ).css( 'overflow', '' );
    }
    if ( sessionStorage.pagecount == 4 && _ulr == '/my_account' ) {
      var $body = ( window.opera ) ? ( document.compatMode == "CSS1Compat" ? $( 'html' ) : $( 'body' ) ) : $( 'html,body' ); //operaFix
      $( '.guide_wrap' ).fadeIn();
      $( '.guide_wrap>div' ).hide();
      $( '.guide_zhangh' ).fadeIn();
      $( 'body' ).css( 'overflow', 'hidden' );
      $body.scrollTop( 280 );
    } else if ( sessionStorage.pagecount == 4 && _ulr != '/my_account' ) {
      sessionStorage.pagecount = 999;
      $( '.guide_wrap' ).hide();
      $( '.guide_wrap>div' ).hide();
      $( 'body' ).css( 'overflow', '' );
    }
    if ( sessionStorage.pagecount == 999 ) {
      $( 'body' ).css( 'overflow', '' );
    }

  } );

  return null;
} );
